#include "mainwindow.h"
#include <QTimer>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setMaximumSize(600,700);
    QTimer *timer=new QTimer(this);
    timer->start(100);

    stopBtn=new QPushButton(this);
    stopBtn->setGeometry(400,150,50,30);
    stopBtn->setText(tr("STOP"));

    flag=true;

    connect(timer,SIGNAL(timeout()),this,SLOT(SimOneStep()));
    connect(stopBtn,SIGNAL(clicked(bool)),this,SLOT(ChangeFlag()));
}

MainWindow::~MainWindow()
{
    delete stopBtn;
}

void MainWindow::ChangeFlag()
{
    flag=!flag;
}

void MainWindow::SimOneStep()
{
    if(flag)
    {
        plot.sim.RunStep();
        repaint();
    }
}


void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    plot.DrawMap(&painter);
    plot.DrawCar(&painter);
    plot.DrawCameraScan(&painter);
}

